package com.lcxw.hxzb.friendcircle.project.system.controller;

import com.lcxw.hxzb.friendcircle.common.utils.DateUtils;
import com.lcxw.hxzb.friendcircle.common.utils.DistanceUtil;
import com.lcxw.hxzb.friendcircle.framework.web.controller.BaseController;
import com.lcxw.hxzb.friendcircle.framework.web.domain.AjaxResult;
import com.lcxw.hxzb.friendcircle.framework.web.page.TableDataInfo;
import com.lcxw.hxzb.friendcircle.project.system.domain.YwpdDynamic;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdCommentService;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdDynamicService;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * 用户动态Controller
 *
 * @author jjp
 * @date 2020-07-20
 */
@RestController
@Api("用户动态")
@RequestMapping("/dynamic")
public class FreindDynamicController extends BaseController {

    @Autowired
    private IYwpdDynamicService ywpdDynamicService;

    /**
     * 查询用户动态列表
     */
    @ApiOperation("查询用户动态列表")
    @PostMapping("/freindList")
    public TableDataInfo list(@RequestBody YwpdDynamic ywpdDynamic) {
        startPage();
        List<YwpdDynamic> list = new ArrayList<>();
        if (ywpdDynamic.getType() == 2) {
            list = ywpdDynamicService.selectFreindList(ywpdDynamic);
        } else {
            list = ywpdDynamicService.selectNearbyList(ywpdDynamic);
        }
        for (int i = 0; i < list.size(); i++) {
            YwpdDynamic dynamic = list.get(i);
            list.get(i)
                .setTimes(DateUtils.getDatePoor(DateUtils.getNowDate(), dynamic.getCreateTime()));
            dynamic.setDistance(DistanceUtil.getDistance(Double.valueOf(dynamic.getLat()),
                Double.valueOf(dynamic.getLng()),
                Double.valueOf(ywpdDynamic.getLat()),
                Double.valueOf(ywpdDynamic.getLng())));
        }
        return getDataTable(list);
    }

}
